﻿easyloader.theme = "gray";
easyloader.locale = "zh_CN";
$(function(){
using(["parser","validatebox"], function () {
        $.parser.auto = false;
		init();
    });
});

var datereg=/\/Date\((\d+)\)\//gi;

function init(){
	$.extend($.fn.validatebox.defaults.rules, {  
        checkNum: {  
            validator: function(value, param) {  
                return /^([0-9]+)$/.test(value);  
            },  
            message: "请输入整数"  
        },  
        checkFloat: {  
            validator: function(value, param) {  
                return /^[+|-]?([0-9]+\.[0-9]+)|[0-9]+$/.test(value);  
            },  
            message: "请输入合法数字"  
        },
		checkDate: {
			validator: function(value,param) {
				return /^[1|2]\d{3}-\d{1,2}-\d{1,2}$/.test(value);
			},
			message: "时间格式为:2016-01-01."
		}
	});
}

//转换asp.net传过来的日期
function aspnet_date(data,strs)
{
	try{
	var dates=strs.split('|');
	var list=data.rows==null?data:data.rows;
	
	
	if(list.length<=0)
	{return data;}
	for(var i=0;i<list.length;i++){
		for(var j=0;j<dates.length;j++)
		{
			var date=list[i][dates[j]];
			if(datereg.test(date))
			{
				
				var now =  eval(date.replace(datereg, "new Date($1)"));
				var year =  now.getFullYear();
      			var month = now.getMonth() + 1;
     			var date = now.getDate();
				list[i][dates[j]]=year+"-"+month+"-"+date;
			}
		}
	}
	
	data.rows=list;
	return data;
	}catch(e)
	{
		return data;
	}
	
}

function rajax(data) {
    try {
        $.messager.progress("close");
        switch (data.code) {
            case 200:
                $.messager.alert('提示', data.msg, 'info');
                break;
            default:
                $.messager.alert('错误', data.msg, 'error');
                break;
        }
    } catch (e) {
        alert(e);
    }
}

function add(a, b) {
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length;
    } catch (f) {
        c = 0;
    }
    try {
        d = b.toString().split(".")[1].length;
    } catch (f) {
        d = 0;
    }
    return e = Math.pow(10, Math.max(c, d)), (mul(a, e) + mul(b, e)) / e;
}

function sub(a, b) {
    var c, d, e;
    try {
        c = a.toString().split(".")[1].length;
    } catch (f) {
        c = 0;
    }
    try {
        d = b.toString().split(".")[1].length;
    } catch (f) {
        d = 0;
    }
    return e = Math.pow(10, Math.max(c, d)), (mul(a, e) - mul(b, e)) / e;
}

function mul(a, b) {
    var c = 0,
        d = a.toString(),
        e = b.toString();
    try {
        c += d.split(".")[1].length;
    } catch (f) {}
    try {
        c += e.split(".")[1].length;
    } catch (f) {}
    return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c);
}

function div(a, b) {
    var c, d, e = 0,
        f = 0;
    try {
        e = a.toString().split(".")[1].length;
    } catch (g) {}
    try {
        f = b.toString().split(".")[1].length;
    } catch (g) {}
    return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), mul(c / d, Math.pow(10, f - e));
}